{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load icons %}

{% block content %}
<div class="page-wrapper">
    <!--block content-->
    <div class="page-header d-print-none">
        <div class="container-xl">
            <div class="row g-2 align-items-center">
                <div class="col">
                    <div class="page-pretitle">
                        Interfaces
                    </div>
                    <h2 class="page-title">
                        {{ compute.name }}
                    </h2>
                </div>
            </div>
        </div>
    </div>

    <!-- Page body -->
    <div class="page-body">
        <div class="container-xl">
            <div class="card">
                <div class="card-header">
                    <ul class="nav nav-tabs card-header-tabs">
                        <li class="nav-item">
                        <a class="nav-link" href="{% url 'overview' compute.id %}">
                            <span>{% icon 'dashboard' %}&nbsp;&nbsp;{% trans "Overview" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                        <a class="nav-link" href="{% url 'instances' compute.id %}">
                            <span>{% icon 'server' %}&nbsp;&nbsp;{% trans "Instances" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                        <a class="nav-link" href="{% url 'storages' compute.id %}">
                            <span>{% icon 'hdd-o' %}&nbsp;&nbsp;{% trans "Storages" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'networks' compute.id %}">
                                <span>{% icon 'sitemap' %}&nbsp;&nbsp;{% trans "Networks" %}</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="#">
                                <span class="text-azure">{% icon 'wifi' %}&nbsp;&nbsp;{% trans "Interfaces" %}</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'nwfilters' compute.id %}">
                                <span>{% icon 'filter' %}&nbsp;&nbsp;{% trans "NWFilters" %}</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'virtsecrets' compute.id %}">
                                <span>{% icon 'key' %}&nbsp;&nbsp;{% trans "Secrets" %}</span>
                            </a>
                        </li>
                        <li class="nav-item ms-auto">
                            {% include 'create_iface_block.html' %}
                        </li>
                    </ul>
                </div>

                <div class="card-body">
                    <p class="text-muted">
                        <!-- Tab1 -->
                        <div class="row">
                            {% if not  ifaces_all %}
                                <div class="col-lg-12">
                                    <div class="alert alert-warning shadow-sm">
                                        <i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "Hypervisor doesn't have any Interfaces" %}
                                    </div>
                                </div>
                            {% else %}
                                {% for iface in ifaces_all %}
                                    <div class="col-12 col-sm-4">
                                        <div class="mb-3 card">
                                            {% if iface.state %}
                                                <div class="ribbon bg-teal">Connect</div>
                                            {% else %}
                                                <div class="ribbon bg-red">Disconnect</div>
                                            {% endif %}

                                            <div class="card-body">
                                                <h3 class="card-title"><a class="card-link text-azure" href="{% url 'interface' compute.id iface.name %}">{{ iface.name }}</a></h3>
                                                <p class="text-muted">
                                                    <div class="row">
                                                        <div class="col-3 col-sm-4">
                                                            <p><strong>{% trans "Type" %}:</strong></p>
                                                            <p><strong>{% trans "IPv4" %}:</strong></p>
                                                            <p><strong>{% trans "MAC" %}:</strong></p>
                                                        </div>
                                                        <div class="col-9 col-sm-8">
                                                            <p>{{ iface.type }}</p>
                                                            <p>{{ iface.ipv4 }}</p>
                                                            <p>{{ iface.mac }}</p>
                                                        </div>
                                                    </div>
                                                </p>
                                            </div>
                                        </div>
                                    </div>
                                {% endfor %}
                            {% endif %}
                        </div>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block script %}
<script>
    $(document).ready(function () {
        $('#itype').change(function (eventObject) {
            if ($(this).val() == 'bridge') {
                $('.bridge_name_form_group').show();
            } else {
                $('.bridge_name_form_group').hide();
            }
        }).change();
        $('#ipv4').change(function (eventObject) {
            if ($(this).val() == 'static') {
                $('.static_ipv4_form_group').show();
            } else {
                $('.static_ipv4_form_group').hide();
            }
        }).change();
        $('#ipv6').change(function (eventObject) {
            if ($(this).val() == 'static') {
                $('.static_ipv6_form_group').show();
            } else {
                $('.static_ipv6_form_group').hide();
            }
        }).change();
    });
</script>
{% endblock %}